<!DOCTYPE html>
<html>
    <head>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="js/log4javascript.js"></script>
        <script type="text/javascript">
            // <![CDATA[
            var log = log4javascript.getLogger("index_html");

            var serverLogTimer;

            function requestCallback(xmlHttp) {
                if (serverLogTimer) {
                    clearTimeout(serverLogTimer);
                }
                serverLogTimer = setTimeout(refreshServerLog, "1000");
            }

            function refreshServerLog() {
//                var logFile = "sessionlog.php?" + (new Date()).getTime();
//                var iframe = document.getElementById("serverLogIFrame");
//                iframe.src = logFile;
                serverLogTimer = null;
            }

            var ajaxAppender = new log4javascript.AjaxAppender("AjaxLogServlet");
            ajaxAppender.setWaitForResponse(true);
            ajaxAppender.setLayout(new log4javascript.HttpPostDataLayout());
            ajaxAppender.setRequestSuccessCallback(requestCallback);
            log.addAppender(ajaxAppender);

            var words = ["Watford", "eased", "their", "relegation", "fears", "with", "a", "win",
                "against", "a", "Charlton", "side", "who", "slipped", "further", "towards", "the",
                "drop", "Don", "Cowie", "drilled", "in", "a", "shot", "to", "put", "the", "Hornets",
                "ahead", "before", "Tresor", "Kandol", "ended", "a", "powerful", "run", "by",
                "rounding", "keeper", "Scott", "Loach", "and", "slotting", "in", "to", "level"
            ];

            var loaded = false;

            function generateRandom() {
                var numberOfEntries = parseInt(document.getElementById("numberOfLogEntries").value);
                for (var i = 0; i < numberOfEntries; i++) {
                    var numberOfWords = 1 + Math.floor(10 * Math.random());
                    var entryWords = [];
                    for (var j = 0; j < numberOfWords; j++) {
                        entryWords.push(words[Math.floor(Math.random() * words.length)]);
                    }
                    var entryMessage = entryWords.join(" ");
                    var levelNum = Math.floor(Math.random() * 6);
                    switch (levelNum) {
                        case 0:
                            log.trace(entryMessage);
                            break;
                        case 1:
                            log.debug(entryMessage);
                            break;
                        case 2:
                            log.info(entryMessage);
                            break;
                        case 3:
                            log.warn(entryMessage);
                            break;
                        case 4:
                            log.error(entryMessage);
                            break;
                        case 5:
                            log.fatal(entryMessage);
                            break;
                    }
                }
            }
            // ]]>
        </script>
    </head>
    <body>
        <div id="container" class="nonav">
            <div id="header">
                <h1><a href="/docs/index.html">log4javascript</a></h1>
            </div>
            <div id="content">
                <div id="nav">
                    <a class="navitem" href="../index.html">home</a>
                    | <a class="navitem" href="http://sourceforge.net/projects/log4javascript" target="_blank" title="Download (opens in new window)">download</a>
                    | <a class="navitem" href="../docs/index.html">docs</a>
                    | <a class="navitem" href="../docs/quickstart.html">quick start</a>
                    | <a class="navitem" href="index.html">demos</a>
                    | <a class="navitem" href="http://log4javascript.org" target="_blank">website</a>
                    | <a class="navitem" href="http://www.timdown.co.uk" target="_blank">timdown.co.uk</a>
                </div>
                <h1>log4javascript Ajax example</h1>
                <p>
                    This demo sends messages to the server via Ajax using log4javascript's
                    <a href="../docs/manual.html#ajaxappender">AjaxAppender</a>. The edition of log4javascript
                    used in this demo is the Production Edition, which only contains one appender (AjaxAppender).
                </p>
                <p>
                    Enter a log message below and click on one of the buttons to log
                    your message at your desired level, or use the "Generate random log entries" option
                </p>
                <div class="example">
                    <h2>Logging</h2>
                    <input type="checkbox" id="enabled" onclick="log4javascript.setEnabled(this.checked)" checked="checked" /> <label for="enabled">logging enabled</label>
                    <br />
                    <input type="text" id="logText" value="Put log message here" />
                    <input type="button" value="trace" onclick="log.trace(document.getElementById('logText').value)" />
                    <input type="button" value="debug" onclick="log.debug(document.getElementById('logText').value)" />
                    <input type="button" value="info" onclick="log.info(document.getElementById('logText').value)" />
                    <input type="button" value="warn" onclick="log.warn(document.getElementById('logText').value)" />
                    <input type="button" value="error" onclick="log.error(document.getElementById('logText').value)" />
                    <input type="button" value="fatal" onclick="log.fatal(document.getElementById('logText').value)" />
                    <br />
                    Generate <input type="text" size="5" id="numberOfLogEntries" value="50" /> random log entries
                    <input type="button" value="go" onclick="generateRandom()" />
                </div>
                <h2>Server posted data log</h2>
<!--                <div class="serverlog">
                    <iframe id="serverLogIFrame" src="blank.html" width="100%" height="100%" frameborder="1"></iframe>
                </div>-->
            </div>
            <br class="clear" />
            <div id="footer">
                <span class="externallinkinfo">
                    <strong>NB.</strong> All external links open in a new window.
                </span>
                Written by Tim Down. <a href="mailto:tim@log4javascript.org">tim@log4javascript.org</a>
                <br />
                log4javascript is distributed under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html"
                                                           title="Apache License, Version 2.0 (opens in new window)" target="_blank">Apache License,
                    Version 2.0</a>
            </div>
        </div>
    </body>
</html>
